/*
Copyright (C) Vincenzo Tilotta 2012 <tailot@gmail.com>

util.js is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your option) any later version.

util.js is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
function logga(myelement){
	console.log(myelement);
}

function rotate(elementid,deg){
	/* for firefox, safari, chrome, etc. */
	$('#'+elementid).css({
        "transform": "rotate("+deg+"deg)",
        "-moz-transform": "rotate("+deg+"deg)",
        "-webkit-transform": "rotate("+deg+"deg)",
        "-o-transform": "rotate("+deg+"deg)"
	});
}
function spriteimageloop(stringimage, positionarray, elementid){
	arrayimage = stringimage.split(",");
	positionarray++;
	if(positionarray >= arrayimage.length){
		positionarray=0;
	}
	$('#'+elementid).attr("src","image/"+arrayimage[positionarray]);
	setTimeout("spriteimageloop('"+stringimage+"',"+positionarray+",'"+elementid+"')",100);
}

/*
 * Muove l'elemento con animazione nella posizione posX posY
 */
function moveXY(posX, posY, elementid){
	 $('#'+elementid).animate({
		 left: posX,
		 top: posY
	 },500);
}

function moveXYnoanimate(posX, posY, elementid){
	$('#'+elementid).css("left",posX);
	$('#'+elementid).css("top",posY);
}
/*
 * posX1, posY1 (orig sprite)
 * posX2, posY2 (destinazione sprite)
 */
function angleByCoordinates(posX1, posY1, posX2, posY2){
	var gradient = Math.atan((posX2-posX1)/(posY2-posY1));
	var angle = (gradient * 180) / Math.PI;
	if((posY2-posY1) > 0){
		return (360-angle)+180;
	}else{
		return angle*-1;
	}
}
function particleStart(posX,posY,pathimage){
	var emitter = new particle_emitter({ image: [pathimage], center: ['50%', '50%'], offset: [0, 0], radius: 0, size: 16, velocity: 50, decay: 2000, rate: 20 }).start();
	emitter.offsetTo(posX, posY);
	setTimeout($.proxy(function(){ emitter.stop(); }, emitter),800);
}

function boot(){
	this.monster = new Sprite("monster",[100,333],"image/monster_off.png","start");
	this.monster.enablemove();
}